package controllers;

import aggregator.EsperAggregator;
import entities.Tag;
import play.db.jpa.Transactional;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;

/**
 * Created with IntelliJ IDEA.
 * User: eagami
 * Date: 03/05/14
 * Time: 16:03
 * To change this template use File | Settings | File Templates.
 */
public class TagsController extends Controller {

    @Transactional(readOnly = true)
    public static Result getAllTags(){
        return ok(Json.toJson(Tag.getAllTags()));

    }
    
    public static Long isInStation(long stationId,int stationX,int stationY,Integer tagX,Integer tagY){
    	if(calculateDistance(stationX, stationY, tagX, tagY) <= 50){
    		return stationId;
    	}
    	return null;
    }
    
    private static double calculateDistance(Integer stationX,Integer stationY,Integer tagX,Integer tagY)
    {
        double Sum = 0.0;
           Sum = Sum + Math.pow(stationX-tagX,2.0);
           Sum = Sum + Math.pow(stationY-tagY,2.0);
        
        return Math.sqrt(Sum);
    }

    public static Result getRealTimeTags(){
        return ok(Json.toJson(EsperAggregator.mLocHelper.values()));
    }
}
